<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>办公用品</title>
    <script src="../../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../../res/js/Tools.js" charset="utf-8"></script>
    <script src="../../../../../res/js/error.js" charset="utf-8"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../../res/images/favicon.ico">
    <link rel="stylesheet" href="../../../../../res/layui/css/layui.css" media="all">
</head>
<body style="padding: 10px">
<form class="layui-form layui-form-pane" action="">
    <input type="hidden" id="pkOfficeSuppliesId" name="pkOfficeSuppliesId"/>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >用品名</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input"  disabled name="officeSuppliesName"
                       id="officeSuppliesName" type="text"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >用品编号</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" id="officeSuppliesCode" placeholder="自动生成" disabled
                       type="text"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">用品类型</label>
            <div class="layui-input-inline">
                <select name="officeSuppliesTypeId" id="officeSuppliesTypeId">
                    <option value="">请选择类型</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">用品规格</label>
            <div class="layui-input-inline">
                <input type="text"  disabled id="officeSuppliesSpecification"
                       lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        </div>
    <div class="layui-form-item">

        <div class="layui-inline">
            <label class="layui-form-label">品牌</label>
            <div class="layui-input-inline">
                <input type="text"  id="officeSuppliesBrand" disabled
                       lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">单价</label>
            <div class="layui-input-inline">
                <input type="text" disabled id="officeSuppliesPrice" lay-verify="required|number" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">单位</label>
            <div class="layui-input-inline">
                <input type="text" disabled id="officeSuppliesUnit" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">库存量</label>
            <div class="layui-input-inline">
                <input type="text"  id="officeSuppliesQuantity"  disabled  autocomplete="off" class="layui-input">
            </div>
        </div>

    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea  disabled id="remark" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-hide" id="uploadDemoView" style="clear: left">
        <input type="hidden" id="officeSuppliesImg" name="officeSuppliesImg"/>
        <img src="" alt="上传成功后渲染" style="max-width: 196px">
    </div>
    <hr/>
    <div class="layui-form-item">
        <div class="layui-input-block" id="flows">
            <input type="button" id="demo3" class="layui-btn layui-btn-primary" value="退出">
        </div>
    </div>
</form>

<script>
    var table2;
    var form = null;
    let pkOfficeSuppliesId=getQueryString("pkOfficeSuppliesId");
    // 修改赋值
    layui.use(['form', 'table','upload', 'laydate'], function () {
        var table = layui.table
            , layer = layui.layer
            , upload = layui.upload
            , laydate = layui.laydate
            , form = layui.form;
        //日期时间范围
        laydate.render({
            elem: '#test101'
            , type: 'datetime'
            , range: true
            , format: 'yyyy年MM月dd日HH时'
        });
        loadType();
        findById(pkOfficeSuppliesId);
        form.render();


        //监听提交
        form.on('submit(demo1)', function (data) {
            let res = postAjax(getRootPath() + "OaOfficeSupplies/addorUpdateOfficeSupplies", data.field);

            if (res.code === 1) {
                layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面
                    //window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3001);
                //window.location.reload();//刷新页面
            } else if (res.code === 500) {

            } else {
                layer.msg("新增失败");
            }
            return false;
        });

        $("#demo3").on("click", function () {
            //询问框
            layer.confirm('是否关闭该页面？', {
                btn: ['是的', '取消'] //按钮
            }, function () {
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                //window.parent.location.reload();//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        });
    });

    function findById(pkOfficeSuppliesTypeId) {
        let url = getRootPath() + "/OaOfficeSupplies/findByIdOfficeSupplies/" + pkOfficeSuppliesId;
        let data = getAjaxById(url);
        $("#pkOfficeSuppliesId").val(data.data.pkOfficeSuppliesId);
        $("#officeSuppliesName").val(data.data.officeSuppliesName);
        $("#officeSuppliesCode").val(data.data.officeSuppliesCode);
        $("#officeSuppliesTypeId").val(data.data.officeSuppliesTypeId);
        $("#officeSuppliesTypeId").attr("disabled","disabled");
        $("#officeSuppliesSpecification").val(data.data.officeSuppliesSpecification);
        $("#officeSuppliesBrand").val(data.data.officeSuppliesBrand);
        $("#officeSuppliesPrice").val(data.data.officeSuppliesPrice);
        $("#officeSuppliesUnit").val(data.data.officeSuppliesUnit);
        $("#officeSuppliesQuantity").val(data.data.officeSuppliesQuantity);
        $("#remark").val(data.data.remark);
        $("#officeSuppliesTypeSuperiorId").val(data.data.officeSuppliesTypeSuperiorId);
        layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', data.data.officeSuppliesImg);
        layui.form.render("select");
    }
    function loadType() {
        var url = getRootPath() + "SuppliesTypeAction/selectType";
        var data = getAjaxById(url);
        $.each(data.data, function (index, item) {
            $("#officeSuppliesTypeId").append("<option value='" + item.pkOfficeSuppliesTypeId + "'>" + item.officeSuppliesTypeName + "</option>");
        });
    }
</script>
</body>
</html>